<!--
 * @Author: 张辰龙 zhangchenlong@julimeng.com
 * @Date: 2025-06-03 09:53:20
 * @LastEditors: 张辰龙 zhangchenlong@julimeng.com
 * @LastEditTime: 2025-06-03 10:12:52
 * @FilePath: /zrreportWxMp/pages/index/components/topHeader.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
	<view>

		<!-- #ifdef H5 -->
		<view class="au-btn">
			<view class="au-btn-text">
				<slot>{{ PageName }}</slot>
			</view>
		</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->

		<view class="au-btn"
			:style="{ 'top': searchBarTop + 'px',height: searchBarHeight + 'px', lineHeight: searchBarHeight + 'px' }">
			<view class="btn-icon">
				<slot name="left">
					<template v-if="isShowBack">
						<uni-icons class="icon" @click="backHome" v-if="!isShowBackHome" type="home" color="#fff"
							size="24"></uni-icons>
						<uni-icons @click="back" v-else type="left" color="#fff" size="24"></uni-icons>
					</template>
				</slot>
			</view>

			<view class="au-btn-text">
				<slot>{{ PageName }}</slot>
			</view>

		</view>
		<!-- #endif -->

	</view>
</template>

<script>
	export default {
		name: 'topHeader',
		props: {
			PageName: {
				type: String,
				default: ''
			},
			isShowBack: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				searchBarTop: 0, //状态栏高度
				searchBarHeight: 0, //胶囊高度
				searchBarWidth: 0,
				isShowBackHome: false,
			}
		},

		methods: {
			backHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
				// let paramsPageClick = {
				// 	Um_Key_ButtonName: '返回首页',
				// 	Um_Key_SourcePage: `报告详情`,
				// }
				// this.$umaTrack.pageClickTrack(paramsPageClick)
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
				// let paramsPageClick = {
				// 	Um_Key_ButtonName: '返回上一个页面',
				// 	Um_Key_SourcePage: `报告详情`,
				// }
				// this.$umaTrack.pageClickTrack(paramsPageClick)
			},
			getHaveRoute() {
				let pages = getCurrentPages()
				if (pages.length > 1) {
					this.isShowBackHome = true
				}
			},
			getHeight() {
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
				//获取胶囊对上高度
				this.searchBarTop = menuButtonInfo.top;
				//获取胶囊高度
				this.searchBarHeight = menuButtonInfo.height;
				//获取胶囊宽度
				// this.searchBarWidth = menuButtonInfo.width + 20;
				this.$emit('get-size', menuButtonInfo)
			}
		},
		created() {
			this.$nextTick(() => {
				// #ifdef MP-WEIXIN
				this.getHeight();
				// #endif
				this.getHaveRoute()

			})
		}
	}
</script>

<style lang="scss" scoped>
	.au-btn {
		position: fixed;
		width: 100%;
		z-index: 120;
		/* #ifdef H5 */
		height: 44px;
		line-height: 44px;
		top: 30rpx;
		/* #endif */



		display: flex;
		justify-content: center;
		align-items: center;

		.au-btn-text {
			font-weight: 600;
			font-size: 36rpx;
			color: #FFFFFF;
		}

		.btn-icon {
			position: absolute;
			left: 30rpx;
			top: 50%;
			transform: translateY(-50%);
		}
	}
</style>